package kr.co.nextree.android.sample.activity;

import kr.co.nextree.android.sample.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class ContextMenuTest extends Activity {
	private static final int MENU_ONE = 0;
	private static final int MENU_TWO = 1;
	private static final int MENU_THREE = 2;
	private static final int MENU_FOUR = 3;
	private static final int MENU_FIVE = 4;
	
	private Button mBtnOpen;
	private Button mBtnClose;
	private LinearLayout mLinearLayout;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.option_menu_layout);
		
		mBtnOpen = (Button)findViewById(R.id.open);
		mBtnOpen.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				openContextMenu(mBtnOpen);
			}
		});
		mBtnClose = (Button)findViewById(R.id.close);
		mLinearLayout = (LinearLayout)findViewById(R.id.body);
		
		registerForContextMenu(mLinearLayout);
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.option_menu, menu);
		
		//menu.setHeaderTitle("메뉴");
		//menu.add(0, MENU_ONE, Menu.NONE, "메뉴1");
		//menu.add(0, MENU_TWO, Menu.NONE, "메뉴2"); 
		//menu.add(0, MENU_THREE, Menu.NONE, "메뉴3");
		//menu.add(0, MENU_FOUR, Menu.NONE, "메뉴4");
	}

	@Override
	public boolean onContextItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case MENU_ONE:
		case MENU_TWO:
		case MENU_THREE:
		case MENU_FOUR:
			Toast.makeText(this, "메뉴선택", Toast.LENGTH_SHORT).show();
			return true;

		}
		return super.onContextItemSelected(item);
	}
	

}
